$(function() {
	//设置根元素字体
	setFontSize(980);

	var token = localStorage.phone;
	$.ajax({
		url: "https://newapp.icandrive.cn/api/set.php",
		type: 'post',
		dataType: 'json',
		data: {
			token: token
		},
		success: function(data) {
			console.log(data);
			if(data.status == 200) {
				$(data.dataing).each(function() {
					$('.portrait').attr('src', this.photo);
					$('.name').val(this.user_name);
					$('.id_number').val(this.ID_number);
					$('.phone').val(this.phone);
					$('.work').val(this.work);
				})
			}
		},
		error: function() {}
	});
	$('.name img').click(function() {
		$('.name input[type=file]').click();
})

}); /*end $function*/

var xhr;

function createXMLHttpRequest() {
	if(window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	} else if(window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	}
}

function UpladFile() {
	var f = document.getElementById("file").value;
	if(!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(f)) {
		layer.msg("请选择正确格式的图片");
		return false;
	}

	var token = localStorage.phone;
	var fileObj = document.getElementById("file").files[0];
	var FileController = 'https://newapp.icandrive.cn/api/studentself_photo.php?token=' + token;
	var form = new FormData();
	form.append("myfile", fileObj);
	createXMLHttpRequest();
	xhr.onreadystatechange = handleStateChange;
	xhr.open("post", FileController, true);
	xhr.send(form);
}

function handleStateChange() {
	if(xhr.readyState == 4) {
		if(xhr.status == 200 || xhr.status == 0) {
			var result = xhr.responseText;
			var json = eval("(" + result + ")");
			setTimeout(function() {
				history.go(0)
			}, 2000)

		}
	}
}

function save_self() {
	var token = localStorage.phone;
	var work = $('.work').val();
	//        var phone=$('.phone').val();

	$.ajax({
		url: 'https://newapp.icandrive.cn/api/set_self.php',
		data: {
			token: token,
			work: work
		},
		dataType: 'json',
		type: 'post',
		success: function(data) {
			if(data.status == 200) {
				layer.msg('保存成功', function() {
					history.go(-1);
				})
			} else {
				layer.msg('系统繁忙，请稍后再试')
				history.go(0)
			}

		},
		error: function() {}
	})
}

/*监听手机返回按键*/
// return_keybord();
